winsafe\uxtheme\handles/
htheme.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::guard::*;
6use crate::kernel::privs::*;
7use crate::ole::privs::*;
8use crate::prelude::*;
9use crate::uxtheme::ffi;
10
11handle! { HTHEME;
12	/// Handle to a
13	/// [theme](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/).
14}
15
16impl HTHEME {
17	/// [`DrawThemeBackground`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-drawthemebackground)
18	/// function.
19	pub fn DrawThemeBackground(
20		&self,
21		hdc: &HDC,
22		part_state: co::VS,
23		rc: RECT,
24		rc_clip: Option<RECT>,
25	) -> HrResult<()> {
26		HrRet(unsafe {
27			ffi::DrawThemeBackground(
28				self.ptr(),
29				hdc.ptr(),
30				part_state.part,
31				part_state.state,
32				pcvoid(&rc),
33				pcvoid_or_null(rc_clip.as_ref()),
34			)
35		})
36		.to_hrresult()
37	}
38
39	/// [`GetThemeAppProperties`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemeappproperties)
40	/// function.
41	#[must_use]
42	pub fn GetThemeAppProperties() -> co::STAP {
43		unsafe { co::STAP::from_raw(ffi::GetThemeAppProperties()) }
44	}
45
46	/// [`GetThemeBackgroundContentRect`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundcontentrect)
47	/// function.
48	#[must_use]
49	pub fn GetThemeBackgroundContentRect(
50		&self,
51		hdc: &HDC,
52		part_state: co::VS,
53		bounds: RECT,
54	) -> HrResult<RECT> {
55		let mut rc_content = RECT::default();
56		HrRet(unsafe {
57			ffi::GetThemeBackgroundContentRect(
58				self.ptr(),
59				hdc.ptr(),
60				part_state.part,
61				part_state.state,
62				pcvoid(&bounds),
63				pvoid(&mut rc_content),
64			)
65		})
66		.to_hrresult()
67		.map(|_| rc_content)
68	}
69
70	/// [`GetThemeBackgroundExtent`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundextent)
71	/// function.
72	#[must_use]
73	pub fn GetThemeBackgroundExtent(
74		&self,
75		hdc: &HDC,
76		part_state: co::VS,
77		rc_content: RECT,
78	) -> HrResult<RECT> {
79		let mut rc_extent = RECT::default();
80
81		HrRet(unsafe {
82			ffi::GetThemeBackgroundExtent(
83				self.ptr(),
84				hdc.ptr(),
85				part_state.part,
86				part_state.state,
87				pcvoid(&rc_content),
88				pvoid(&mut rc_extent),
89			)
90		})
91		.to_hrresult()
92		.map(|_| rc_extent)
93	}
94
95	/// [`GetThemeBackgroundRegion`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundregion)
96	/// function.
97	#[must_use]
98	pub fn GetThemeBackgroundRegion(
99		&self,
100		hdc: &HDC,
101		part_state: co::VS,
102		rc: RECT,
103	) -> HrResult<DeleteObjectGuard<HRGN>> {
104		let mut hrgn = HRGN::NULL;
105		unsafe {
106			HrRet(ffi::GetThemeBackgroundRegion(
107				self.ptr(),
108				hdc.ptr(),
109				part_state.part,
110				part_state.state,
111				pcvoid(&rc),
112				hrgn.as_mut(),
113			))
114			.to_hrresult()
115			.map(|_| DeleteObjectGuard::new(hrgn))
116		}
117	}
118
119	/// [`GetThemeColor`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemecolor)
120	/// function.
121	#[must_use]
122	pub fn GetThemeColor(&self, part_state: co::VS, prop: co::TMT) -> HrResult<COLORREF> {
123		let mut color = COLORREF::default();
124		HrRet(unsafe {
125			ffi::GetThemeColor(
126				self.ptr(),
127				part_state.part,
128				part_state.state,
129				prop.raw(),
130				color.as_mut(),
131			)
132		})
133		.to_hrresult()
134		.map(|_| color)
135	}
136
137	/// [`GetThemeMargins`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthememargins)
138	/// function.
139	#[must_use]
140	pub fn GetThemeMargins(
141		&self,
142		hdc_fonts: Option<&HDC>,
143		part_state: co::VS,
144		prop: co::TMT,
145		draw_dest: Option<&RECT>,
146	) -> HrResult<MARGINS> {
147		let mut margins = MARGINS::default();
148		HrRet(unsafe {
149			ffi::GetThemeMargins(
150				self.ptr(),
151				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
152				part_state.part(),
153				part_state.state(),
154				prop.raw(),
155				pcvoid_or_null(draw_dest),
156				pvoid(&mut margins),
157			)
158		})
159		.to_hrresult()
160		.map(|_| margins)
161	}
162
163	/// [`GetThemeMetric`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthememetric)
164	/// function.
165	#[must_use]
166	pub fn GetThemeMetric(
167		&self,
168		hdc_fonts: Option<&HDC>,
169		part_state: co::VS,
170		prop: co::TMT,
171	) -> HrResult<i32> {
172		let mut val = 0i32;
173		HrRet(unsafe {
174			ffi::GetThemeMetric(
175				self.ptr(),
176				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
177				part_state.part(),
178				part_state.state(),
179				prop.raw(),
180				&mut val,
181			)
182		})
183		.to_hrresult()
184		.map(|_| val)
185	}
186
187	/// [`GetThemePartSize`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemepartsize)
188	/// function.
189	#[must_use]
190	pub fn GetThemePartSize(
191		&self,
192		hdc_fonts: Option<&HDC>,
193		part_state: co::VS,
194		draw_dest: Option<&RECT>,
195		esize: co::THEMESIZE,
196	) -> HrResult<SIZE> {
197		let mut sz = SIZE::default();
198		HrRet(unsafe {
199			ffi::GetThemePartSize(
200				self.ptr(),
201				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
202				part_state.part(),
203				part_state.state(),
204				pcvoid_or_null(draw_dest),
205				esize.raw(),
206				pvoid(&mut sz),
207			)
208		})
209		.to_hrresult()
210		.map(|_| sz)
211	}
212
213	/// [`GetThemePosition`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemeposition)
214	/// function.
215	#[must_use]
216	pub fn GetThemePosition(&self, part_state: co::VS, prop: co::TMT) -> HrResult<POINT> {
217		let mut pt = POINT::default();
218		HrRet(unsafe {
219			ffi::GetThemePosition(
220				self.ptr(),
221				part_state.part(),
222				part_state.state(),
223				prop.raw(),
224				pvoid(&mut pt),
225			)
226		})
227		.to_hrresult()
228		.map(|_| pt)
229	}
230
231	/// [`GetThemePropertyOrigin`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemepropertyorigin)
232	/// function.
233	#[must_use]
234	pub fn GetThemePropertyOrigin(
235		&self,
236		part_state: co::VS,
237		prop: co::TMT,
238	) -> HrResult<co::PROPERTYORIGIN> {
239		let mut origin = co::PROPERTYORIGIN::default();
240		HrRet(unsafe {
241			ffi::GetThemePropertyOrigin(
242				self.ptr(),
243				part_state.part(),
244				part_state.state(),
245				prop.raw(),
246				origin.as_mut(),
247			)
248		})
249		.to_hrresult()
250		.map(|_| origin)
251	}
252
253	/// [`GetThemeRect`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemerect)
254	/// function.
255	#[must_use]
256	pub fn GetThemeRect(&self, part_state: co::VS, prop: co::TMT) -> HrResult<RECT> {
257		let mut rc = RECT::default();
258		HrRet(unsafe {
259			ffi::GetThemeRect(
260				self.ptr(),
261				part_state.part(),
262				part_state.state(),
263				prop.raw(),
264				pvoid(&mut rc),
265			)
266		})
267		.to_hrresult()
268		.map(|_| rc)
269	}
270
271	/// [`IsThemeBackgroundPartiallyTransparent`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-isthemebackgroundpartiallytransparent)
272	/// function.
273	#[must_use]
274	pub fn IsThemeBackgroundPartiallyTransparent(&self, part_state: co::VS) -> bool {
275		unsafe {
276			ffi::IsThemeBackgroundPartiallyTransparent(
277				self.ptr(),
278				part_state.part,
279				part_state.state,
280			) != 0
281		}
282	}
283
284	/// [`IsThemePartDefined`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-isthemepartdefined)
285	/// function.
286	#[must_use]
287	pub fn IsThemePartDefined(&self, part_state: co::VS) -> bool {
288		unsafe { ffi::IsThemePartDefined(self.ptr(), part_state.part, part_state.state) != 0 }
289	}
290}